package com.teen9g.infoplatformserver.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teen9g.entity.Advice;
import com.teen9g.entity.AdviceLike;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AdviceMapper extends BaseMapper<Advice> {

    @Delete("delete from advice_like where id = #{id}")
    int deleteLikeById(Integer id);

    @Select("select count(*) from advice_like " +
            "where advice_id = #{adviceId} and user_id = #{userId}")
    Integer selectLikeTrack(@Param("adviceId") Integer adviceId,
                            @Param("userId") Integer userId);

    @Delete("delete from advice_like " +
            "where advice_id = #{id} and user_id = #{userId}")
    int deleteLikeTrack(@Param("userId") Integer userId, @Param("id") Integer id);

    @Update("update advice set advice_like = advice_like + #{updateCount} " +
            "where advice_id = #{id}")
    int updateLike(@Param("id") Integer id, @Param("updateCount") int updateCount);

    @Insert("insert into advice_like (advice_id, user_id, created_at) " +
            "values (#{adviceId}, #{userId},#{createdAt})")
    void insertLikeTrack(AdviceLike adviceLike);


    List<Advice> getByPage(@Param("adviceCategory") String adviceCategory,
                           @Param("adviceAuthor") String adviceAuthor,
                           @Param("adviceStatus") String adviceStatus,
                           @Param("adviceContent") String adviceContent,
                           @Param("order") Integer order);
}
